package bgg4j;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class QueryResult extends Game {

	QueryResult(Element elem, Bgg bgg) throws BggException {
		super(elem, bgg);
		// TODO 自動生成されたコンストラクター・スタブ
	}
	
	public String getName(){
		return this.getChildText("name");
	}
	
	public int getYear(){
		return Integer.valueOf(this.getAttributeText("yearpublished"));
	}
	
	public 
    /*package*/ static List<QueryResult> constructQueryResult(Document doc,
            Bgg bgg) throws BggException{
            if (null == doc) {
                return new ArrayList<QueryResult> (0);
            } else {
                try {
                    ensureRootNodeNameIs("games", doc.getDocumentElement());
                    NodeList list = doc.getDocumentElement().getElementsByTagName(
                            "game");
                    int size = list.getLength();
                    List<QueryResult> statuses = new ArrayList<QueryResult>(size);
                    for (int i = 0; i < size; i++) {
                        Element status = (Element) list.item(i);
                        statuses.add(new QueryResult(status, bgg));
                    }
                    return statuses;
                } catch (BggException te) {
                    return new ArrayList<QueryResult>(0);
                }
            }
        }

}
